package com.baidu.health.service;

import com.baidu.health.util.resFaqVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.health.pojo.TbTaskSituation;
import com.baidu.health.service.TbTaskSituationService;
import com.baidu.health.mapper.TbTaskSituationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbTaskSituationServiceImpl extends ServiceImpl<TbTaskSituationMapper, TbTaskSituation>
    implements TbTaskSituationService{

    @Autowired
    private TbTaskSituationMapper tbTaskSituationMapper;

    //--每天凌晨执行
    //----------------秒 分 时 日
    //@Scheduled(cron = "0 0 0 1/1 * ? ")
    //@Scheduled(cron = "0 0/5 * * * *")
    @Override
    public resFaqVo taskSituation(TbTaskSituation tbTaskSituation) {
        Date data=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM-dd");
        String a=simpleDateFormat.format(data );
        System.out.println("---"+a);

        tbTaskSituation.setSituationStarttime(a);
        List<TbTaskSituation> list=tbTaskSituationMapper.selectBytime(tbTaskSituation);

        if (list.size()>0){
            return new resFaqVo(300, "任务已经成功", null);
        }else{
            tbTaskSituation.setSituationStarttime(a);
            tbTaskSituationMapper.insert(tbTaskSituation);
            return new resFaqVo(200, "任务提交成功", null);
        }


//        Calendar cl=Calendar.getInstance();
//        cl.setTime(data);
//        cl.set(Calendar.HOUR_OF_DAY, 0);
//        cl.set(Calendar.MINUTE, 0);
//        cl.set(Calendar.SECOND, 0);
//        String b=simpleDateFormat.format(cl.getTime());
//        System.out.println("-------"+b);
    }

    //@Scheduled(cron = "0 0 0 1/1 * ? ")
    @Override
    public resFaqVo taskSituations(TbTaskSituation tbTaskSituation) {
        Date data=new Date();
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyy-MM-dd");
        String a=simpleDateFormat.format(data );
        System.out.println("---"+a);

        tbTaskSituation.setSituationStarttime(a);
        List<TbTaskSituation> list=tbTaskSituationMapper.selectBytime(tbTaskSituation);
        if (list.size()>0){
            return new resFaqVo(300, "已经完成任务", null);
        }else{
            tbTaskSituation.setSituationPic("未完成");
            tbTaskSituationMapper.insert(tbTaskSituation);
            return new resFaqVo(200, "任务未完成", null);
        }

    }

    @Override
    public resFaqVo taskSituationsList(TbTaskSituation tbTaskSituationlist) {
        List<TbTaskSituation> list=tbTaskSituationMapper.selectByTid(tbTaskSituationlist);
        return new resFaqVo(200, "成功", list);
    }
}




